﻿#@head() 
#@header()
<title>报表查询逻辑</title> 
#@aside("datanalysis")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
<div class="content-wrapper">
	<section class="content">
		<div class="nav-tabs-custom">
            <ul class="nav nav-tabs"> 
             <li class="active"><a href="#(path)/admin/page/datanalysis-apphelp">报表查询逻辑</a></li> 
            </ul>
            <div class="tab-content">
              <div class="tab-pane active" id="tab_1">
				<div class="box-body" id="ruleinfos" >
					<div style="height:50px;">
						<div align="right" style="width:120px;float:left;line-height:35px;">报表名称：</div>
						<div style="width:30%;float:left">
							<input id="name" type="text" class="form-control" placeholder="报表名称">
						</div>
					</div>
					<div style="clear:both;height:50px;">
						<div align="right" style="width:120px;float:left;line-height:35px;">报表SQL主体：</div>
						<div style="width:30%;float:left">
							<textarea align="left" id="contents" rows="5" style="width:100%"> 
							
							</textarea> 
						</div>
					</div>
					<div style="clear:both;height:50px;">
						<div align="right" style="width:120px;float:left;line-height:35px;">备注：</div> 
						<div style="width:50%;float:left">
							<input id="summary" type="text" style="width:50%;float:left" class="form-control" placeholder="备注">
						</div>
					</div>
					<div style="clear:both;height:50px;">
						<div align="right" style="width:120px;float:left;line-height:35px;">列名：</div>
						<div style="width:50%;float:left">
							<input id="titles" type="text" style="width:50%;float:left" class="form-control" placeholder="列名">
						</div>
					</div>
					<div style="clear:both;"> 
						<hr>
						<button type="button" id="addrule"  class="btn btn-success">增加</button>
						<div align="right" style="width:120px;float:left;line-height:35px;">条件1名称：</div>
						<div style="width:50%;float:left;height:50px;">
							<input id="params_name1" type="text" style="width:20%;float:left" class="form-control" placeholder="条件名称">
							<span style="margin-left:15px;float:left;line-height:35px;">数据类型：</span>
							<select id="params_type1" style="width:20%;float:left" class="form-control" >
							  <option value ="data">Data</option>
							  <option value ="string">String</option>
							</select>
							<span style="margin-left:15px;float:left;line-height:35px;">字段名：</span>
							<input id="params_field1" type="text" style="width:20%;float:left" class="form-control" placeholder="字段名">
						</div> 
						<div style="clear:both;height:50px;">
							<div align="right" style="width:120px;float:left;line-height:35px;">条件对应AND：</div>
							<div style="width:50%;float:left">
								<input id="params_contents1" type="text" style="width:80%;float:left"  class="form-control" placeholder="条件对应AND">
							</div>
						</div>
					</div>
				</div>
				<div class="box-footer">
					<button id="submit_setrule" type="submit" style="margin-left:50px;" class="btn btn-info ">提交</button>
				</div>
              </div>
            </div> 
            <!-- /.tab-content -->
          </div> 
	</section> 
</div>
#@footer()
<script id="rule" type="text/x-jquery-tmpl">
	<div style="clear:both;">
		<hr>
		<button type="button" class="btn btn-danger delrule">删除</button> 
		<div align="right" style="width:120px;float:left;line-height:35px;">条件${i}名称：</div>
		<div style="width:50%;float:left;height:50px;">
			<input id="params_name${i}" type="text" style="width:20%;float:left" class="form-control" placeholder="条件名称">
			<span style="margin-left:15px;float:left;line-height:35px;">数据类型：</span>
			<select id="params_type${i}" style="width:20%;float:left" class="form-control" >
			    <option value ="data">Data</option>
				<option value ="string">String</option>
			</select>
			<span style="margin-left:15px;float:left;line-height:35px;">字段名：</span>
			<input id="params_field${i}" type="text" style="width:20%;float:left" class="form-control" placeholder="字段名">
		</div> 
		<div style="clear:both;height:50px;">
			<div align="right" style="width:120px;float:left;line-height:35px;">条件对应AND：</div>
			<div style="width:50%;float:left">
				<input id="params_contents${i}" type="text" style="width:80%;float:left"  class="form-control" placeholder="条件对应AND">
			</div>
		</div>
	</div>
</script>
<script> 
var i = 1;
$("#addrule").click(function(){
	i++;
	$("#rule").tmpl(i).appendTo('#ruleinfos');
	$(".delrule").click(function(){
		$(this).parent().remove(); 
	});
}); 
var params;
var paramsarray = new Array();
$("#submit_setrule").click(function(){
	for(j=1;j<=i;j++){
		paramsarray.push({name:$("#params_name"+j).val(),field:$("#params_field"+j).val(),type:$("#params_type"+j).val(),contents:$("#params_contents"+j).val()}); 
	}
	params = JSON.stringify(paramsarray);
	var name = $("#name").val(); 
	var contents = $("#contents").val();
	var summary = $("#summary").val();
	var titles = $("#titles").val();
	console.log(name);
	console.log(contents);
	console.log(summary);
	console.log(name);
	console.log(params); 
	ajax("#(path)/sqlReport/edit?aes=0&token=#(session.token??)&contents="+contents+"&summary="+summary,{titles:titles,name:name,params:params},function(ruleinfo){
		if(ruleinfo.code=='success'){
			layer.msg("创建成功！", {icon:1,time:1000},function(){
				//location.href="#(path)/admin/page/datanalysis-reportlist"
			});
		}else if(ruleinfo.code=='error'){
			layer.msg(ruleinfo.msg, {icon:2,time:1000});
		}
	});
});

function GetRequest() {  
	var url = location.search; //获取url中"?"符后的字串  
	var theRequest = new Object();  
	if (url.indexOf("?") != -1) {  
		var str = url.substr(1);  
		strs = str.split("&");  
		for(var i = 0; i < strs.length; i ++) {  
			theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);  
		}  
	}  
	return theRequest;  
}  
</script>
</body>
</html>

